<template>
  <div class="page-box">
    <div class="page-header">
      <div class="back" @click="goback">
        <el-icon><ArrowLeftBold /></el-icon>
      </div>
      <div class="title">评论</div>
    </div>
    <div class="content-box">
      <div class="content">
        <el-input type="textarea" :rows="6" v-model="form.comment" placeholder="请输入评论" />
      </div>
      <div class="rating-box">
        <template v-for="(item, index) in 5" :key="index">
          <div class="star" @click="changeRating(index)">
            <template v-if="form.rating > index">
              <img src="../images/like-2.png" />
            </template>
            <template v-else>
              <img src="../images/like-1.png" />
            </template>
          </div>
        </template>
      </div>
    </div>
    <div class="bottom-box">
      <el-button type="primary" @click="submit">提交评论</el-button>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useMobileStore } from "@/stores/modules/mobile";
import { submitComment } from "@/api/modules/mobile";
const route = useRoute();
const router = useRouter();

const form = ref<any>({
  orderId: "",
  comment: "",
  rating: 1,
  userId: useMobileStore().userId
});

onMounted(async () => {
  const query = route.query;
  if (query.orderId) {
    form.value.orderId = Number(query.orderId);
  }
});

const submit = async () => {
  const params = JSON.parse(JSON.stringify(form.value));
  await submitComment(params);

  router.go(-1);
};

const goback = () => {
  router.go(-1);
};

const changeRating = index => {
  form.value.rating = index + 1;
};
</script>
<style scoped lang="scss">
.page-box {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #f3f0f0;
  .page-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 40px;
    background-color: #ffffff;
    border-bottom: 1px solid #333333;
    .back {
      position: absolute;
      top: 12px;
      left: 12px;
    }
  }
  .bottom-box {
    position: absolute;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: calc(100% - 24px);
    height: 60px;
    padding: 12px;
    background-color: #ffffff;
  }
  .content-box {
    width: calc(100% - 56px);
    height: auto;
    padding: 12px;
    margin: 16px 16px 0;
    font-size: 13px;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 5px 1px #33333350;
    .content {
      width: 100%;
      margin-bottom: 12px;
    }
    .rating-box {
      display: flex;
      justify-content: flex-end;
      width: 100%;
      .star {
        width: 24px;
        height: 24px;
        margin-left: 4px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
</style>
